#ifndef __QUEUE_HTTP_CLIENT__
#define __QUEUE_HTTP_CLIENT__

#include <sys/types.h> 
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>

#define TCP_CLIENT_BUFFER_SIZE 4095

/** @} */
/* Just in case your linefeed isn't the one the other end is expecting. */
#if !CHARSET_EBCDIC
/** carrige return */
#define CR 13
/** linefeed */
#define LF 10

#define SP 32
#define HT 9
/** carrige return /Line Feed Combo */
#define CRLF "\015\012"

#else /* CHARSET_EBCDIC */

#define CR '\r'
#define LF '\n'
#define SP ' '
#define HT '\t'
#define CRLF "\r\n"
#endif /* CHARSET_EBCDIC */

typedef enum
{
	TCP_CLIENT_BUFSTAT_UNSET = 0,
	TCP_CLIENT_BUFSTAT_READY,
	TCP_CLIENT_BUFSTAT_FULL,
	TCP_CLIENT_BUFSTAT_END,
	TCP_CLIENT_BUFSTAT_FAILED
}
client_buffer_stat;

typedef struct tcp_client
{
	int sock;
	struct sockaddr_in addr; 
	socklen_t addr_len;

	/* application type command. */
	int cmd;

	/* if one request get success the 'ready' will set to 1 */
	int ready;

	int keep_alive;
	
	struct {
		char head[TCP_CLIENT_BUFFER_SIZE + 1];	
		char *cur;
		size_t used;
		size_t size;
		client_buffer_stat status;
	}
	buffer;
}
tcp_client;

/* read one char from tcp_client buffer, when at the end of buffer, read a new one from socket. */
char tcp_readchar(tcp_client *client);

size_t  tcp_readline(tcp_client *client, char *dest, size_t maxlen);

ssize_t tcp_read    (tcp_client *client, void *dest, size_t length);

ssize_t tcp_write   (tcp_client *client, const void *data, size_t length);

#endif

